module.exports = {
  userLogin: userLogin,
  onLogin: onLogin
};

const user_url = "https://www.hkzhaoscut.top/normalUser/login"
//用户的登录
function userLogin(username) {
  return new Promise((resolve, reject) => {
    wx.login({
      success: function (res) {
        console.log("这是userLogin成功函数的res", res)
        if (res.code) {
          //发起网络请求
          wx.request({
            url: user_url,
            method: "GET",
            data: {
              code: res.code,
              username: username
            },
            success: function (res) {
              console.log("userLogin请求后台成功", res)
              resolve(res.data)
            },
            fail: function (res) {
              console.log("userLogin失败")
            }
          })
        }
      },
      fail: function (res) {
        console.log("这是onLogin函数的res", res)
      }

    })
  })


}

function onLogin() {
  wx.login({
    success: function (res) {
      console.log("这是onLogin成功函数的res", res)
      if (res.code) {
        //发起网络请求
        wx.request({
          url: base_url,
          data: {
            code: res.code,
            username: "testMiniProgram"
          },
          success: function (res) {
            console.log(res)
            getUserInfo()
            // const self = this
            // if (逻辑成功) {
            //   //获取到用户凭证 存儲 3rd_session 
            //   var json = JSON.parse(res.data.Data)
            //   wx.setStorage({
            //     key: "third_Session",
            //     data: json.third_Session
            //   })
            //   getUserInfo()
            // } else {

            // }
          },
          fail: function (res) {

          }
        })
      }
    },
    fail: function (res) {
      console.log("这是onLogin函数的res", res)
    }

  })
}

